using System;
using System.Collections.Generic;
using System.Text;

namespace tKitchen
{
    public class UnitPresenter
    {
        tKitchenMain domain;
        UnitInput inputForm;


        public UnitPresenter(tKitchenMain domainIn)
        {
            domain = domainIn;
            inputForm = new UnitInput(this);
            
            PopulateGrid();
          

        }


        internal void AddUnit(string nameIn, string abbrevIn, string descrIn)
        {
            Unit tempUnit = new Unit();
            tempUnit.Name = nameIn;
            tempUnit.Abbrev = abbrevIn;
            tempUnit.Descr = descrIn;

            domain.AddObject(tempUnit);

            PopulateGrid();

        }

        internal void UpdateUnit(Unit tempUnit)
        {
            domain.UpdateObject(tempUnit);
            inputForm.RefreshGrid();
        }


        private void PopulateGrid()
        {
            List<Unit> unitList = domain.GetUnitList();
            inputForm.SetDataSource(unitList);
            inputForm.RefreshGrid();
        }

        public void ShowForm()
        {
            inputForm.Show();
        }
    }
}
